﻿using System.Runtime.CompilerServices;

namespace AuthCenter.Common
{
    /// <summary>
    /// 扩展类
    /// 里面定义扩展方法
    /// 用this作为类型扩展关键字
    /// 类和方法必须都是静态的
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// 扩展字符串转数字
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int ToInt32(this string? value)
        {
            if(value==null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(value);
            }
        }

        /// <summary>
        /// 根据身份证计算出出生年月日
        /// </summary>
        /// <param name="carId"></param>
        /// <returns></returns>
        public static string getBirthByCarid(this string carId)
        {
            string result=carId.Substring(6,8);
            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string shijian(this DateTime date)
        {
            return date.ToString("yyyy-MM-dd");
        }


    }
}
